#include "mainwindow.h"
#include "ui_mainwindow.h"

// OpenGL着色语言中文高清版.pdf
// 3.1 着色器对的实例
// 用颜色平滑的表示一个表面温度
// 温度及颜色范围可参数化

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("温度显示");

    widget3D = new Widget3D();

    this->ui->horizontalLayout->addWidget(widget3D);

    this->ui->lineEdit->setText("40.0");
    this->ui->lineEdit_2->setText("-40.0");
    widget3D->setTempRange(this->ui->lineEdit->text().toFloat(), this->ui->lineEdit_2->text().toFloat());

    hotColor = QColor(255.0, 0.0, 0.0);
    cooleColor = QColor(0.0, 0.0, 255.0);

    widget3D->setHottestColor((float)hotColor.red()/255.0, (float)hotColor.green()/255.0, (float)hotColor.blue()/255.0);
    widget3D->setCoolestColor((float)cooleColor.red()/255.0, (float)cooleColor.green()/255.0, (float)cooleColor.blue()/255.0);

    QPixmap p1(ui->label_6->size());
    p1.fill(hotColor);
    ui->label_6->setPixmap(p1);

    QPixmap p2(ui->label_6->size());
    p2.fill(cooleColor);
    ui->label_8->setPixmap(p2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_lineEdit_textChanged(const QString &arg1)
{
    (void)arg1;
    widget3D->setTempRange(this->ui->lineEdit->text().toFloat(), this->ui->lineEdit_2->text().toFloat());
}

void MainWindow::on_lineEdit_2_textChanged(const QString &arg1)
{
    (void)arg1;
    widget3D->setTempRange(this->ui->lineEdit->text().toFloat(), this->ui->lineEdit_2->text().toFloat());
}

void MainWindow::on_pushButton_clicked()
{
    // hot
    hotColor = QColorDialog::getColor(hotColor, this);
    widget3D->setHottestColor((float)hotColor.red()/255.0, (float)hotColor.green()/255.0, (float)hotColor.blue()/255.0);
    const_cast<QPixmap*>(ui->label_6->pixmap())->fill(hotColor);

}

void MainWindow::on_pushButton_2_clicked()
{
    // coole
    cooleColor = QColorDialog::getColor(cooleColor, this);
    widget3D->setCoolestColor((float)cooleColor.red()/255.0, (float)cooleColor.green()/255.0, (float)cooleColor.blue()/255.0);
    const_cast<QPixmap*>(ui->label_8->pixmap())->fill(cooleColor);
}
